import React, { Component } from 'react'
import { createBrowserHistory } from "history";
import RouterContext from "./RouterContext"


export default class BrowserRouter extends Component {
  constructor(props) {
    super(props);
    this.state = {
      location: createBrowserHistory().location
    };
    this.history = createBrowserHistory();
    this.unlisten = this.history.listen(location => {
      this.setState({ location });
    });
  }
  static computeRootMatch(pathname) {
    return { path: "/", url: "/", params: {}, isExact: pathname === "/" };
  }
  render() {

    // return <RouteContext>
    return <RouterContext.Provider
      value={{
        history: this.history,
        location: this.state.location,
        match: BrowserRouter.computeRootMatch(this.state.location.pathname)
      }}>
      {this.props.children}
    </RouterContext.Provider>
  }
}
